package com.cat.dao.common.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.cat.dao.common.RoleDao;
import com.cat.entity.TbRole;
import com.cat.entity.TbUser;

/**
 * @ClassName: ExecutionContextDaoImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author Jiangcl
 * @date 2012-2-21下午12:38:36
 * 
 */
@Repository
@SuppressWarnings("unchecked")
public class RoleDaoImpl extends BaseDaoImpl<TbRole, Integer> implements RoleDao {
	
	
	public List<TbRole> getRoleList(TbRole role) {
		Criteria c = getSession().createCriteria(TbRole.class);
		if(role.getRoleName()!=null&&!role.getRoleName().equals("")){
		   c.add(Restrictions.ilike("roleName", "'%"+role.getRoleName()+"%'"));
		}
		
		if(c.list()!=null){
			return c.list();
		}
		return null; 
	}

	@Override
	public TbRole checkRole(TbRole role) {
		Criteria c = getSession().createCriteria(TbRole.class);
		c.add(Restrictions.eq("roleName", role.getRoleName()));
		if(c.list()!=null&&c.list().size()>0){
			return (TbRole) c.list().get(0);
		}
		return null;
	}
}
